package yijy.arrayExamples;

import java.util.Arrays;

/**
 * Created by yijy on 2017/8/11.
 * 假定某个宾馆有3层，第一层4个房间，第二层3个房间，第三层5个房间,以下是每层房间入住情况
 *              1        2         3        4      5
 *  第三层              Jane                         Rose
 *  第二层：   Linda   Lucy      Lily
 *  第一层：   Tom    Milk       Jack        null
 */
public class MultiArrays {

    public static void main(String[] args) {
        String[] floor1={"Tom" ,"Milk" ,"Jack",null};
        String[] floor2={"Linda" ,"Lucy" ,"Lily"};
        String[] floor3={null ,"Milk" ,null,null,"Rose"};

        //上面等价于
        String[][] floor = {{"Tom" ,"Milk" ,"Jack",null},
                            {"Linda" ,"Lucy" ,"Lily"},
                            {null ,"Milk" ,null,null,"Rose"}};
        for(int i=0;i<floor.length;i++){
            for(int j=0;j<floor[i].length;j++){
                System.out.print(floor[i][j]+"\t");
            }
            System.out.println();
        }
        MultiArrays multiArr = new MultiArrays();
        int[] arr = new int[101];
        int[] arr1 = new int[101];
        int[] arr2 = new int[101];
        for(int i=0;i<=100;i++){
            arr[i]= (int)(Math.random()*100);
        }
        System.arraycopy(arr,0,arr1,0,arr.length);
        System.arraycopy(arr,0,arr2,0,arr.length);
        System.out.println("arr数组是："+Arrays.toString(arr));
        System.out.println("arr1数组是："+Arrays.toString(arr1));
        multiArr.QuickSort(arr);
        multiArr.bubbleSort(arr1);
        System.out.println("----------------------数组自带排序算法-----------");
        long start = System.currentTimeMillis();
        Arrays.sort(arr2);
        long end = System.currentTimeMillis();
        System.out.println(end-start);
        System.out.println(Arrays.toString(arr2));

    }


    public void QuickSort(int[] arr){
        System.out.println("----------------------这是快速排序算法-----------");
        long start = System.currentTimeMillis();
        for(int i=0;i<arr.length-1;i++){
            for(int j=i+1;j<=arr.length-1;j++){
                if(arr[i]>arr[j]){
                    int temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] =temp;
                }
            }
            System.out.println(Arrays.toString(arr));
        }
        long end = System.currentTimeMillis();
        System.out.println(end-start);
    }

    public void bubbleSort(int[] arr){
        System.out.println("----------------------这是冒泡排序算法-----------");
        if(null==arr || arr.length==0){

        }
        for(int i=0;i<arr.length-1;i++){
            for(int j=0;j<arr.length-i-1;j++){
                if(arr[j]>arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1]=temp;
                }
            }
        }
        System.out.println(Arrays.toString(arr));
    }

}
